#include <iostream>

using namespace std;

struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Solution {
public:
    ListNode* middleNode(ListNode* head) {
        ListNode* l1 = head;
        ListNode* l2 = head;
        while (l2 != nullptr && l2->next != nullptr) {
            l1 = l1->next;
            l2 = l2->next->next;
        }
        return l1;
    }
};